﻿<Window x:Class="YouTube.YouTubeWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:YouTube"
    DataContext="{Binding RelativeSource={RelativeSource Self}}"
    Title="YouTube Plug-In" Width="640" Height="480">
    <Window.CommandBindings>
        <CommandBinding Command="MediaCommands.TogglePlayPause" CanExecute="TogglePlayPauseCommand_CanExecute" Executed="TogglePlayPauseCommand_Executed" />
        <CommandBinding Command="MediaCommands.Play" CanExecute="PlayCommand_CanExecute" Executed="PlayCommand_Executed" />
        <CommandBinding Command="MediaCommands.Pause" CanExecute="PauseCommand_CanExecute" Executed="PauseCommand_Executed" />
        <CommandBinding Command="MediaCommands.Stop" CanExecute="StopCommand_CanExecute" Executed="StopCommand_Executed" />
    </Window.CommandBindings>
    <Window.Resources>
        <local:TimeToDoubleConverter x:Key="TimeToDoubleConverter" />
        <DataTemplate DataType="{x:Type local:YouTubeVideo}">
            <local:VideoItem MouseDoubleClick="VideoItem_MouseDoubleClick" />
        </DataTemplate>
    </Window.Resources>
    <Grid>
        <DockPanel>
            <DockPanel DockPanel.Dock="Top" Margin="5,5,5,0">
                <Button DockPanel.Dock="Right" Command="ApplicationCommands.Open" CommandParameter="{Binding ElementName=searchTextBox,Path=Text}">Search...</Button>
                <TextBox Name="searchTextBox" Margin="0,0,5,0" />
            </DockPanel>
            <ListBox Margin="5" ItemsSource="{Binding Videos}" IsSynchronizedWithCurrentItem="True" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                     Name="videosListBox">
                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem">
                        <Setter Property="Margin" Value="4" />
                    </Style>
                </ListBox.ItemContainerStyle>
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <WrapPanel IsItemsHost="True" />
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
            </ListBox>
        </DockPanel>
        
        <ContentControl Name="mediaPlayer" MouseDoubleClick="mediaPlayer_MouseDoubleClick" Visibility="Collapsed"
                        IsHitTestVisible="True" MinWidth="320" MinHeight="240" HorizontalAlignment="Center" VerticalAlignment="Center">
            <Grid Background="Black">
                <TextBlock SnapsToDevicePixels="True" Background="Black" Foreground="White" Text="Loading..." HorizontalAlignment="Center" VerticalAlignment="Center" />
                <DockPanel>
                    <StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Center">
                        <Button Command="MediaCommands.Play" CommandTarget="{Binding ElementName=mediaElement}" Content="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}" />
                        <Button Command="MediaCommands.Pause" CommandTarget="{Binding ElementName=mediaElement}" Content="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}" />
                        <Button Command="MediaCommands.Stop" CommandTarget="{Binding ElementName=mediaElement}" Content="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}" />
                        <Separator Margin="4,0,4,0" />
                        <Slider Name="mediaElementSlider" Width="100" />
                        <Separator Margin="4,0,4,0" />
                        <TextBlock Name="mediaElementTextBlock" Foreground="White" VerticalAlignment="Center" />
                        <Separator Margin="4,0,4,0" />
                        <Button Click="playInMpc_Click">MPC</Button>
                    </StackPanel>
                    <MediaElement Name="mediaElement" LoadedBehavior="Manual" UnloadedBehavior="Manual" IsHitTestVisible="False"
                              MediaOpened="mediaElement_MediaOpened" MediaEnded="mediaElement_MediaEnded" MediaFailed="mediaElement_MediaFailed" BufferingStarted="mediaElement_BufferingStarted" BufferingEnded="mediaElement_BufferingEnded" />
                </DockPanel>
                <TextBlock Name="mediaElementStatus" HorizontalAlignment="Left" VerticalAlignment="Top" Foreground="White" />
            </Grid>
        </ContentControl>
    </Grid>
</Window>
